package com.atguigu.spring5.testdemo;

import com.atguigu.spring5.bean.Book;
import com.atguigu.spring5.service.BookService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @date: 2021/12/7 11:28
 * @description:
 */
public class TestSpring5 {
    @Test
    public void testAdd(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        Book book = new Book();
        book.setUserId(1);
        book.setUserName("java");
        book.setuStatus("0");
        bookService.addBook(book);
    }
    @Test
    public void testUpdate(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        Book book = new Book();
        book.setUserId(1);
        book.setUserName("java2");
        book.setuStatus("1");
        bookService.updateBook(book);
    }
    @Test
    public void testDelete(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        bookService.deleteBook(1);
    }
    @Test
    public void testSeleteCount(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        System.out.println(bookService.seleteCount());
    }
    @Test
    public void testSeleteBook(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        System.out.println(bookService.seleteBook(1));
    }
    @Test
    public void testSelectAllBook(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        System.out.println(bookService.selectAllBook());
    }
    @Test
    public void testBatchAllBook(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        List<Object[]> list=new ArrayList<>();
        Object[] o1= {"3","go","2"};
        Object[] o2= {"4","c100","3"};
        list.add(o1);
        list.add(o2);
        bookService.batchAll(list);
    }
    @Test
    public void testBatchUpdateBook(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        List<Object[]> list=new ArrayList<>();
        Object[] o1= {"3","go1111","2"};
        Object[] o2= {"4","c10022222","3"};
        list.add(o1);
        list.add(o2);
        bookService.batchUpdate(list);
    }
    @Test
    public void testBatchDeleteBook(){

        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        List<Object[]> list=new ArrayList<>();
        Object[] o1= {"2"};
        Object[] o2= {"3"};
        list.add(o1);
        list.add(o2);
        bookService.batchDelete(list);
    }
}
